package com.dongnao.jack.loadbalance;

import java.util.List;
import java.util.Random;

import com.dongnao.jack.service.store.ParseServiceFactory;

public class RandomBalance implements Balance {

    private String flag = "random";

    @Override
    public NodeRegisterInfo getRegisterInfo(List<String> registerList, String type) {

        Random random = new Random();
        String registerInfo = registerList.get(random.nextInt(registerList.size()));
        NodeRegisterInfo info = new NodeRegisterInfo();
        info.setHost(ParseServiceFactory.getParseService(type).parseHost(registerInfo));
        info.setPort(ParseServiceFactory.getParseService(type).parsePort(registerInfo));
        info.setType(type);
        info.setRegisterInfo(registerInfo);

        return info;
    }

    @Override
    public boolean support(String anFlag) {

        return flag.equals(anFlag);
    }

}
